home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tsptp.zip / TPBENCH.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-09  |  5KB  |  187 lines

  1. (******************************************************************************)
  2. (*                                 TPBENCH.PAS                                *)
  3. (*                                                                            *)
  4. (*  Routines for internal timer used by the Pascal benchmarks.                *)
  5. (*                                                                            *)
  6. (******************************************************************************)
  7.  
  8. UNIT TPBench;
  9.  
  10. INTERFACE
  11.  
  12.   USES Dos;
  13.  
  14.   TYPE
  15.     (*** Benchmarking types.  Note that Turbo 6-byte Reals have no exact    ***)
  16.     (*** equivalent in TopSpeed Pascal.  The TopSpeed Emulator however,     ***)
  17.     (*** support 4, 8, and 10 byte floating point reals and an 8 byte fixed ***)
  18.     (*** point real that are equivalent to the Turbo Single, Double,        ***)
  19.     (*** Extended and Comp types respectively.  Because of this floating    ***)
  20.     (*** point benchmarks should be run on a system with a coprocessor for  ***)
  21.     (*** comparison.                                                        ***)
  22.  
  23.     BmInt   = LONGINT;              (* -214783648..214783647, signed 32-bit   *)
  24.     BmReal  = REAL;                 (*    2.9E-39..1.7E+38  , 6 bytes         *)
  25.  
  26.     (*** Timing                                                             ***)
  27.  
  28.     BmTimeT   = LONGINT;            (* Suitable type for max seconds          *)
  29.     BmCounter = LONGINT;            (* Suitable type for max loops            *)
  30.  
  31.   CONST
  32.     MINNULLTIME   = 1;              (* Null loop time in seconds              *)
  33.     MINBENCHTIME  = 60;             (* Bench loop time in scoonds, 60 is good *)
  34.  
  35.   VAR
  36.     DummyVar : BOOLEAN;             (* Global variable for side-effects       *)
  37.  
  38.  
  39. (** STARTTIMER ****************************************************************
  40.  *
  41.  *  Synopsis:
  42.  *
  43.  *    StartTimer;
  44.  *
  45.  *  Description:
  46.  *
  47.  *    StartTime starts the benchmark timer.
  48.  *)
  49.  
  50.   PROCEDURE StartTimer;
  51.  
  52.  
  53. (** NULLTIMESUP ***************************************************************
  54.  *
  55.  *  Synopsis:
  56.  *
  57.  *    NullTimesUp;
  58.  *
  59.  *  Description:
  60.  *
  61.  *    NullTimesUp stops the timer when the NULL timing loop is complete.
  62.  *)
  63.  
  64.   FUNCTION NullTimesUp: BOOLEAN;
  65.  
  66. (** BENCHTIMESUP **************************************************************
  67.  *
  68.  *  Synopsis:
  69.  *
  70.  *    BenchTimesUp;
  71.  *
  72.  *  Description:
  73.  *
  74.  *    BenchTimesUp stops the timer when the NULL timing loop is complete.
  75.  *)
  76.  
  77.   FUNCTION BenchTimesUp: BOOLEAN;
  78.  
  79.  
  80. (** REPORTTIMES ***************************************************************
  81.  *
  82.  *  Synopsis:
  83.  *
  84.  *    ReportTimes;
  85.  *
  86.  *  Description:
  87.  *
  88.  *    ReportTimes reports the benchmark times and stats.  Note that the
  89.  *    calculated results for LoopOverhead, TotalTime and Loops per second
  90.  *    are prone to any floating point errors.  Therefore you may wish to
  91.  *    check these results manually.
  92.  *)
  93.  
  94.   PROCEDURE ReportTimes;
  95.  
  96.  
  97. (** DUMMY *********************************************************************
  98.  *
  99.  *  Synopsis:
  100.  *
  101.  *    Dummy;
  102.  *
  103.  *  Description:
  104.  *
  105.  *    Dummy is a dummy procedure used to calculate the looping overhead in a
  106.  *    benchmark.  In order to prevent it being optimised out of existence it
  107.  *    must introduce a side effect.  In this case we modify the exported
  108.  *    variable DummyVar.
  109.  *)
  110.  
  111.   PROCEDURE Dummy;
  112.  
  113. IMPLEMENTATION
  114.  
  115.   VAR
  116.     Hours,
  117.     Minutes,
  118.     Seconds,
  119.     Hundredths  : WORD;
  120.  
  121.     NullLoops,
  122.     BenchLoops  : BmCounter;
  123.  
  124.     NullLoopTime,
  125.     BenchLoopTime,
  126.     StartTime,
  127.     NullTime,
  128.     BenchTime   : BmTimeT;
  129.  
  130.  
  131.   PROCEDURE StartTimer;
  132.   BEGIN
  133.     Dos.GetTime(Hours, Minutes, Seconds, Hundredths);
  134.     StartTime := (((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths;
  135.   END;
  136.  
  137.  
  138.   FUNCTION NullTimesUp{: BOOLEAN};
  139.   BEGIN
  140.     Dos.GetTime(Hours, Minutes, Seconds, Hundredths);
  141.     NullTime    := ((((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths)-StartTime;
  142.     NullLoops   := NullLoops + 1;
  143.     NullTimesUp := (NullTime >= NullLoopTime);
  144.   END;
  145.  
  146.  
  147.   FUNCTION BenchTimesUp{: BOOLEAN};
  148.   BEGIN
  149.     Dos.GetTime(Hours, Minutes, Seconds, Hundredths);
  150.     BenchTime     := ((((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths)-StartTime;
  151.     BenchLoops    := BenchLoops + 1;
  152.     BenchTimesUp  := (BenchTime >= BenchLoopTime);
  153.   END;
  154.  
  155.  
  156.   PROCEDURE ReportTimes;
  157.     VAR
  158.       RLoopOverhead  : REAL;
  159.       RTotalTime     : REAL;
  160.   BEGIN
  161.     RLoopOverhead := (NullTime/NullLoops)*BenchLoops;
  162.     RTotalTime    := BenchTime-RLoopOverhead;
  163.     WriteLn('Benchmark times in seconds');
  164.     WriteLn('NullTime         : ', NullTime/100:0:2);
  165.     WriteLn('BenchTime        : ', BenchTime/100:0:2);
  166.     WriteLn('Null loops       : ', NullLoops);
  167.     WriteLn('Bench loops      : ', BenchLoops);
  168.     WriteLn('LoopOverhead     : ', RLoopOverhead/100:0:2);
  169.     WriteLn('TotalTime        : ', RTotalTime/100:0:2);
  170.     WriteLn('Loops per second : ', BenchLoops/(RTotalTime/100):0:2);
  171.   END;
  172.  
  173.  
  174.   PROCEDURE Dummy;
  175.   BEGIN
  176.     DummyVar := NOT DummyVar
  177.   END;
  178.  
  179. BEGIN
  180.   NullLoopTime  := MINNULLTIME*100;
  181.   BenchLoopTime := MINBENCHTIME*100;
  182.   NullLoops     := 0;
  183.   BenchLoops    := 0;
  184.   DummyVar      := TRUE;
  185. END.
  186.  
  187.